package br.com.rafael.gestorinvestimentos.DAO;

import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

import br.com.rafael.gestorinvestimentos.model.Balanco;
import br.com.rafael.gestorinvestimentos.model.Operacao;

public class BalancoDAO {
	private Session session;
	
	public BalancoDAO(Session session){
		this.session = session;
	}	
	
	public void insert (Balanco balanco){
		this.session.save(balanco);
	}
	
	public void update (Balanco balanco){
		this.session.merge(balanco);
	}
	
	public void delete (Balanco balanco){
		this.session.delete(balanco);
	}
	
	public Balanco getBalanco (int id){
		return (Balanco) session.load(Balanco.class, id);
	
	}
	
	public Balanco getBalanco (Date data){
		Query q = this.session.createQuery("from Balanco as balanco where balanco.dataReferencia = :balancoData").setParameter("balancoData", data);
		return (Balanco) q.uniqueResult();
	}

	public List getList (){
		return this.session.createCriteria(Balanco.class).list();
	}
}
